package com.greate.community.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class RecommendCacheService {
    @Autowired
    private RedisTemplate redisTemplate;

    private static final String RECOMMEND_KEY_PREFIX = "recommend:posts:";

    // 写入推荐帖子ID列表到Redis
    public void cacheRecommendPosts(int userId, List<Integer> postIds, long expireSeconds) {
        String key = RECOMMEND_KEY_PREFIX + userId;
        redisTemplate.opsForValue().set(key, postIds, expireSeconds, TimeUnit.SECONDS);
    }

    // 从Redis读取推荐帖子ID列表
    public List<Integer> getRecommendPosts(int userId) {
        String key = RECOMMEND_KEY_PREFIX + userId;
        return (List<Integer>) redisTemplate.opsForValue().get(key);
    }
} 